
var validator = require('validator');
var express = require('express');
var router = express.Router();

var config = require('../../config');
var project = require('../../controllers/project');
var projectService = require('../../service/project');

router.param('id', function(req, res, next, id) {
	if (!validator.objectid(id)) return res.status(400).json({msg: '项目不存在。'});

	projectService.findProjectById(id, function(err, project){
		if(err) return next(err);
		if(!project) return res.status(400).json({msg: '项目不存在。'});

		req.project = project;
		next();
	});
});

// 查看
router.get('/:id', project.view);

// 新增
router.post('/', project.create);

module.exports = router;